//
//  BootWindow.m
//  boot
//
//  Created by Demi on 07/03/2017.
//  Copyright © 2017 Azazie. All rights reserved.
//

#import "BootWindow.h"
#import "TXFire.h"
#import "BootAnimationViewController.h"



@interface BootWindow ()

@property (nonatomic, strong) BootWindowConfiguration *configuration;
@property (nonatomic, weak) BootWindow *bootWindow;

@end

@implementation BootWindow



#pragma mark - initializer

- (instancetype)initWithFrame:(CGRect)frame configuration:(BootWindowConfiguration *)configuration
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        
        _configuration = configuration;
        
        BootAnimationViewController *vc = [[BootAnimationViewController alloc] initWithWindow:self];
        self.rootViewController = vc;
    }
    return self;
}

- (void)dismissWithStyle:(BootDismissalAnimationStyle)style {
    switch (style) {
        case BootDismissalAnimationStyleNone: {
            self.hidden = YES;
            self.configuration.completion();
        }
            break;
        case BootDismissalAnimationStyleFadeOut: {
            [UIView animateWithDuration:BOOT_WINDOW_ANIMATION_DURATION
                             animations:^{
                                 self.alpha = 0;
                             } completion:^(BOOL finished) {
                                 self.configuration.completion();
                             }];
        }
            break;
        case BootDismissalAnimationStyleLeftTransition: {
            [UIView animateWithDuration:BOOT_WINDOW_ANIMATION_DURATION
                             animations:^{
                                self.transform = CGAffineTransformMakeTranslation(-self.tx_width, 0);
                             } completion:^(BOOL finished) {
                                 self.configuration.completion();
                             }];
        }
            break;
    }
}

@end

@implementation BootWindowConfiguration

- (instancetype)initWithType:(BootType)type hasSignedIn:(BOOL)signedIn completion:(void (^)(void))completion signInCallback:(void (^)(void))signInCallback signUpCallback:(void (^)(void))signUpCallback
{
    self = [super init];
    if (self)
    {
        _type = type;
        _hasSignedIn = signedIn;
        _completion = [completion copy];
        _signInCallback = [signInCallback copy];
        _signUpCallback = [signUpCallback copy];
    }
    return self;
}

@end
